<template>
  <fieldset>
    <legend>子组件</legend>
    <h1>{{ msg }}</h1>
    <h2>父传子：{{ v }}</h2>
    <button @click="handle">子传父</button>
    <h2>bro传来的值:{{ msg2 }}</h2>
  </fieldset>
</template>

<script>
export default {
  data() {
    return {
      msg: "子组件属性",
      toParent: "子传父的值",
      msg2: "",
    };
  },
  // props:["v"],
  props: {
    v: {
      type: String,
      default() {
        return "默认值";
      },
      require: true,
    },
  },
  methods: {
    handle() {
      this.$emit("rec", this.toParent);
    },
  },
  mounted() {
    this.$bus.$on("getBro", (input) => {
      console.log(input);
      this.msg2 = input;
    });
  },
};
</script>

<style></style>
